/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) {
  const {currentUser} = initialState ?? {};
  console.log('currentUser = ', currentUser)

  return {
    canAdmin: currentUser?.superAdmin,
    canMenuAuth: (route: any): boolean => {
      const r = !!(currentUser?.superAdmin || currentUser?.auths.find((e) => e.indexOf(route.code) !== -1))
      console.log('route = ', route, ' r = ', r);
      return r
    },
    canAuth: (name: string): boolean => {
      const r = !!(currentUser?.superAdmin || currentUser?.auths.find((e) => e.indexOf(name) !== -1));
      console.log('name = ', name, ' r = ', r);
      return r;
    },
  };
}
